package com.minimalist.common.config.bucket;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.Objects;

/**
 * @author 11987
 */
@Configuration
public class IpRateLimitConfig{
    @Value("${ip-rate-limit.capacity}")
    private int capacity;
    @Value("${ip-rate-limit.refill-interval}")
    private int refillInterval;
    @Value("${ip-rate-limit.duration}")
    private Duration duration;

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getRefillInterval() {
        return refillInterval;
    }

    public void setRefillInterval(int refillInterval) {
        this.refillInterval = refillInterval;
    }

    public Duration getDuration() {
        return duration;
    }

    public void setDuration(Duration duration) {
        this.duration = duration;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        IpRateLimitConfig that = (IpRateLimitConfig) o;
        return capacity == that.capacity &&
                refillInterval == that.refillInterval &&
                Objects.equals(duration, that.duration);
    }

    @Override
    public int hashCode() {
        return Objects.hash(capacity, refillInterval, duration);
    }

    @Override
    public String toString() {
        return "IpRateLimitConfig{" +
                "capacity=" + capacity +
                ", refillInterval=" + refillInterval +
                ", duration=" + duration +
                '}';
    }
}
